<?php
// +----------------------------------------------------------------------
// |ZBPHP[基于ThinkPHP5.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2019 http://www.benbenwangluo.com
// +----------------------------------------------------------------------
// | Author 似水星辰 [ 2630481389@qq.com ]
// +----------------------------------------------------------------------
// | 中犇软件 技术六部 出品
// +----------------------------------------------------------------------

namespace app\customer\admin;
use app\admin\admin\Base;


/**
 * 仪表盘
 * @package app\customer\controller
 */
class Index extends Base
{
    /**
     * 客服列表
     * @author 晓风<215628355@qq.com>
     * @return mixed
     */
    public function index()
    {        
        $result["usernum"] = \app\customer\model\Session::where(1)->count();        
        $result["today"] = \app\customer\model\Session::whereTime("create_time","today")->count();  
        
        $result["chat"] = \app\customer\model\Chat::whereTime("create_time","today")->where("form_type",1)->count();
        $result["reply"] =  \app\customer\model\Chat::whereTime("create_time","today")->where("form_type",2)->count();
        
        $user1 = $recharge = [];
        for($i=7;$i>=0;$i--) {
            $daystr = date('Y-m-d', strtotime("-$i day"));
            $searchstr = "TO_DAYS(from_unixtime(create_time,'%Y-%m-%d'))=TO_DAYS('" . $daystr . "')";
            $apCount = \app\customer\model\Chat::where($searchstr)->where("form_type",1)->count();
            $MoneyCount = \app\customer\model\Chat::where($searchstr)->where("form_type",2)->count();
            $dateArray[] = date('m-d', strtotime("-$i day"));
            $user1[] = $apCount;
            $recharge[] = $MoneyCount;
        }
       $result["users"]  = implode(',',$user1);       
       $result["recharge"]  = implode(',',$recharge);
       $result["date"] = $dateArray;
       $this->assign($result); 
       return $this->fetch();//显示
    }

    /**
     * 新增
     * @author 晓风<215628355@qq.com>
     * @return mixed
     */
    public function add()
    {
       
        
    
      
    }
     /**
     * 删除
     * @author 晓风<215628355@qq.com>
     * @return mixed
     */
    public function delete($ids = null){
       
    }
     /**
     * 编辑
     * @author 晓风<215628355@qq.com>
     * @return mixed
     */
    public function edit(int $status){
   
    }
    
    public function get_new_message(){
     
    }
    
    
    public function searchStore(){
         // 查询
        $key = input('key/s', '');
        if ($key == '') {
            return '';
        }
        $page = input('page/d', 1);
        // 数据列表
        $data_list = \app\store\model\Store::where('store_id', 'like', '%' . $key . '%')
            ->whereOr('store_name', 'like', '%' . $key . '%')    
            ->field('store_id,store_name,store_logo')
            ->paginate(20);
        $results = [];
        foreach ($data_list as $v) {
            $v['store_logo'] = \app\store\model\Store::getStoreLogoUrl($v['store_id'],$v['store_logo']);
            $img = '<img src="'.$v['store_logo'].'" height="18px"/>&nbsp;&nbsp;';
            $str = $img . $v['store_id'] . '/' . $v['store_name'];
            $results[] = ['id' => $v['store_id'], 'text' => $str];
        }
        $data['results'] = $results;
        $data['pagination'] = $data_list->currentPage() == $data_list->lastPage() ? ['more' => true] : ['more' => false];
        return json($data, JSON_UNESCAPED_UNICODE);
    }
}